package com.ocom.payconfig.dao;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.card.EntityXfAccountInfo;
import com.ocom.payconfig.vo.GetListRechargeRVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface IDaoAccountInfo extends BaseMapper<EntityXfAccountInfo> {

    @Select({"<script>",
            "select at.deposit,at.cost_fee,c.card_state,p.com_id,p.p_id,p.p_code,p.p_name,a.id as account_id,a.account_no,a.account_name,a.acc_type_id,at.acc_type_name,a.account_recharge_money," +
                    "a.account_subsidy_money, c.card_no,c.end_date,c.use_time_now,c.use_ls_now,p.dept_id,d.dept_name\n" +
                    ", case when LENGTH(p.p_photo_url) >10 then '已上传' else '未上传' end photoAdmin"+
                    ", case when LENGTH(p.p_photo_url2) >10 then '已上传' else '未上传' end photoUser"+
                    ",GROUP_CONCAT( distinct mc.merch_id,'#',sn.pay_way  SEPARATOR ';' " +
                            " ) as signInfoIds" +
                    ",count(palm.p_id) palmNum "+
                    " from personnel_info p " +
                    "left join xf_sign_no sn  on p.com_id=sn.com_id and sn.p_id=p.p_id and sn.status=1 "+
                    "left join personnel_palmprint palm on p.com_id=palm.com_id and  p.p_id=palm.p_id "+
                    "left join xf_merchant_info mc on p.com_id=mc.com_id and sn.merch_id=mc.merch_id "+
                    "left join dept_info d on p.dept_id=d.dept_id " +
                    "inner join xf_account_info a on p.p_id=a.p_id  and p.com_id=a.com_id  " +
                    " left join xf_account_type at \n" +
                    "on a.acc_type_id=at.acc_type_id and a.com_id=at.com_id " +
                    "left join card_info as c on p.p_id=c.p_id and p.com_id = c.com_id and c.card_state in (0,1) "+
                    "where p.status=0 and a.account_state=0 and p.com_id=#{comId} "+
                    " <when test=\"deptIdsList!=null and deptIdsList.size() &gt; 0 \" > "+
                    " AND (p.dept_id is null or p.dept_id  in " +
                    " <foreach collection='deptIdsList' item='id' open='(' separator=',' close='))'> "+
                    " #{id} "+
                    " </foreach> "+
                    "</when>"+
                    " <when test=\"pId!=null and pId!=0\"> "+
                    " AND p.p_id =  #{pId} "+
                    " </when> "+
                    " <when test=\"pName!=null and pName!=''\"> "+
                    " AND p.p_name like concat('%', #{pName}, '%') "+
                    " </when> "+
                    " <when test=\"pCode!=null and pCode!=''\" > "+
                    " AND p.p_code  like concat('%', #{pCode}, '%') "+
                    " </when> "+
                    " <when test=\"cardNo!=null and cardNo!=''\" > "+
                    " AND c.card_no  like concat('%', #{cardNo}, '%') "+
                    " </when> "+
                    " <when test=\"accountNo!=null and accountNo!=''\" > "+
                    " AND a.account_no  like concat('%', #{accountNo}, '%') "+
                    " </when> "+
                    " <when test=\"accTypeId!=null and accTypeId!=''\" > "+
                    " AND a.acc_type_id=#{accTypeId} "+
                    " </when> "+
                    " group by  p.com_id,p.p_id "+
                    "order by p.update_time desc",
            "</script>"})
    List<GetListRechargeRVo> GetListRecharge(Long comId, List<Integer> deptIdsList, String pCode,
                                             String pName, String cardNo, String accountNo, Long accTypeId,Long pId);
}
